package com.anhuanjia.tools.eao.controller;

import java.util.UUID;

import org.springframework.util.StringUtils;

import com.anhuanjia.tools.eao.bean.EaoProjectEnvOverview2;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.data.Transaction;
import com.efastsoft.framework.utility.StringUtil;

/**
 *
 * @ClassName: ProjectEnvOverview2UI
 * @Description: 对项目周围环境概括图进行操作
 * @author wangqiangqiang
 * @date 2018年9月20日下午2:50:55
 *  
 */

@Alias(value = "projectEnvOverview2")
public class ProjectEnvOverview2UI extends UIFacade{
	/**
	 * @Title: saveOrUpdateProjectEnvOverview
	 * @Description:  项目周围环境概括图添加或修改
	 * @author wangqiangqiang
	 * @date 2018年9月20日下午3:06:04
	 */
	@Priv(loginType = LoginType.Member)
	public void saveOrUpdateProjectEnvOverview(){
		Transaction transaction=new Transaction();
		String id=$V("Id");
		if(StringUtils.isEmpty(id)){
			//该图片为新加图片
			EaoProjectEnvOverview2 projectEnvOverview2=new EaoProjectEnvOverview2();
			projectEnvOverview2.setId(UUID.randomUUID().toString());			
			projectEnvOverview2.setValue(this.Request);
			transaction.insert(projectEnvOverview2);
			if(transaction.commit()){
				s("添加项目周围环境图片成功");
			}else{
				f("添加项目周围环境图片失败");
			}
		}else{
		 //进行更新
			DataTable dt = new Q("select *  from eao_project_env_overview2 where Id=?", id).fetch();
			EaoProjectEnvOverview2 projectEnvOverview2=new EaoProjectEnvOverview2();			
			projectEnvOverview2.setValue(dt.get(0));
			projectEnvOverview2.setValue(this.Request);
			transaction.update(projectEnvOverview2);
			if (transaction.commit()) {
				s("保存项目周围环境图片成功");
			} else {
				f("保存项目周围环境图片失败");
			}	
		}
	}
	/**
	 * 
	 * @Title: findAllProjectEnvOverview
	 * @Description: 根据(项目id)查询所有周围环境情况
	 * @author wangqiangqiang
	 * @date 2018年9月20日下午3:09:47
	 */
	@Priv(loginType = LoginType.Member)
	public void findAllProjectEnvOverview(){
		String project_id=$V("ProjectId");
		DataTable projectEnvOverviewDt = new Q("select * from eao_project_env_overview2 where ProjectId =? ",project_id)
				.fetch();
		this.Response.put("projectEnvOverviewDt", projectEnvOverviewDt);
	}
	/**
	 * 
	 * @Title: deleteProjectEnvOverviewByID
	 * @Description: 根据单个图片id删除图片
	 * @author wangqiangqiang
	 * @date 2018年9月20日下午3:39:50
	 */
	@Priv(loginType = LoginType.Member)
	public void deleteProjectEnvOverviewByID(){
		String id=$V("Id");
		if(StringUtil.isNotEmpty(id)){
			Transaction transaction = new Transaction();
			DataTable deleteProjectEnvOverviewDt = new Q("select * from eao_project_env_overview2 where Id = ?", id).fetch();
			if(deleteProjectEnvOverviewDt.getRowCount()!=0){
				EaoProjectEnvOverview2 projectEnvOverview2=new EaoProjectEnvOverview2();	 
				projectEnvOverview2.setValue(deleteProjectEnvOverviewDt.get(0));
				transaction.delete(projectEnvOverview2);
				if(transaction.commit()){
					s("删除项目周围环境图片成功");
				}else{
					f("删除项目周围环境图片失败");
				}
			}
		}
	}
	
}
